﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "课程成绩底单");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		checked = false;
			
		if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
			
			checked = true;
	
	
			/* 载入教学任务 */
			switch(taskType){
				case 'C':
					sql = "SELECT
								tsk.tsk_id,
								c.course_name,
								cc.cat_name,
								i.institute_name,
								tch.tch_name,
								tsk.cidx,
								tch.tch_id,
								tm.academic_year,
								tm.academic_term,
								c.course_code,
								c.course_credit,
								tsk.term_id
							FROM
								t_common_task tsk
								INNER JOIN t_course c ON tsk.cid = c.cid
								INNER JOIN t_course_catalog cc ON c.cat_id = cc.cat_id
								INNER JOIN t_institute i ON i.institute_id = c.institute_id
								INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
								INNER JOIN t_term tm ON tsk.term_id = tm.term_id
							WHERE
								 tsk.tsk_id = :tsk_id ";
					break;
				case 'P':
					sql = "SELECT
								tsk.tsk_id,
								c.course_name,
								cc.cat_name,
								i.institute_name,
								tch.tch_name,
								tsk.cidx,
								tch.tch_id,
								tm.academic_year,
								tm.academic_term,
								c.course_code,
								c.course_credit,
								tsk.term_id
							FROM
								t_task tsk
								INNER JOIN t_course c ON tsk.cid = c.cid 
								INNER JOIN t_course_catalog cc ON c.cat_id = cc.cat_id 
								INNER JOIN t_institute i ON i.institute_id = c.institute_id 
								INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id 
								INNER JOIN t_term tm ON tsk.term_id = tm.term_id 
							WHERE
								 tsk.tsk_id = :tsk_id ";
					break;
				case 'R':
					sql = "SELECT
								tsk.tsk_id,
								c.course_name,
								cc.cat_name,
								i.institute_name,
								tch.tch_name,
								tsk.cidx,
								tch.tch_id,
								tm.academic_year,
								tm.academic_term,
								c.course_code,
								c.course_credit,
								tsk.term_id
							FROM
								t_reopen_task tsk 
								INNER JOIN t_course c ON tsk.cid = c.cid 
								INNER JOIN t_course_catalog cc ON c.cat_id = cc.cat_id 
								INNER JOIN t_institute i ON i.institute_id = c.institute_id 
								INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id 
								INNER JOIN t_term tm ON tsk.term_id = tm.term_id 
							WHERE
								 tsk.tsk_id = :tsk_id ";
					break;
				case 'T':
					sql = "SELECT
								tsk.tsk_id,
								c.course_name,
								cc.cat_name,
								i.institute_name,
								tch.tch_name,
								tsk.cidx,
								tch.tch_id,
								tm.academic_year,
								tm.academic_term,
								c.course_code,
								c.course_credit,
								tsk.term_id 
							FROM
								t_sport_task tsk
								INNER JOIN t_course c ON tsk.cid = c.cid 
								INNER JOIN t_course_catalog cc ON c.cat_id = cc.cat_id 
								INNER JOIN t_institute i ON i.institute_id = c.institute_id 
								INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id 
								INNER JOIN t_term tm ON tsk.term_id = tm.term_id 
							WHERE
								 tsk.tsk_id = :tsk_id ";
					break;
			}

			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="tsk_id", value=taskId, cfsqltype="cf_sql_varchar" );
			
			rs_task = queryObj.execute(sql = sql).getResult();
			
			/* 学校信息 */
			sql = "	SELECT
						  t.sch_id,
						  t.sch_name,
						  t.sch_name_eng,
						  t.sch_address,
						  t.sch_zipcode,
						  t.sch_citycode,
						  t.sch_establish,
						  t.sch_host,
						  t.sch_type,
						  t.sch_prop
					FROM
						t_school t";
						
			queryObj = new Query( datasource=application.dnsSlave );
			
			rs_school = queryObj.execute( sql=sql ).getResult();
			
			/* 成绩数据 */
			
			sql = "	SELECT
						sm.stu_id,stu.stu_name,clz.cls_name,clz.grade,
						sm.retaking,
						sm.mark_mode,sm.mark_result,sm.mark_note,sm.mark_final  
					FROM
						t_student_mark sm 
						INNER JOIN t_student stu ON stu.stu_id = sm.stu_id 
						INNER JOIN t_class clz ON stu.cls_id = clz.cls_id 
					WHERE
						sm.task_id = :taskId 
					ORDER BY
						sm.stu_id";
						
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			
			rs_chooser = queryObj.execute( sql=sql ).getResult();
			
			rowPerPage = 40;
	
			if ( rs_chooser.recordCount mod rowPerPage ) {
				totlePageCount = int(rs_chooser.recordCount/rowPerPage) + 1;
			}
			else {
				totlePageCount = int(rs_chooser.recordCount/rowPerPage);
			}
			
			/*是否需要单开一页显示统计数据*/
			totalCount = rs_chooser.recordCount + 12;
			
			if ( totalCount mod rowPerPage ) {
				totlePageCount2 = int(totalCount/rowPerPage) + 1;
			}
			else {
				totlePageCount2 = int(totalCount/rowPerPage);
			}
	
			pageRowBegin = 1;
			pageRowEnd = min(rowPerPage, rs_chooser.recordCount);
			
			tagCode = "CJDD-" & rs_task.term_id & "," & rs_task.course_code & "," & rs_task.cidx;

		}
		
		num1 = 0; //90分以上人数
		num2 = 0; //80~89分人数
		num3 = 0; //70~79分人数
		num4 = 0; //60~69分人数
		num5 = 0; //不及格人数
		
		num_normal = 0; //实考总人数
		num_absent = 0; //缺考
		num_delayed = 0; //缓考
		num_ignored = 0; //免修
		num_violated = 0; //违纪
		
		num_avg = 0;
		mark_total = 0;//只对百分制

		
		for ( i=1; i LTE rs_chooser.recordCount; i++){
			
			markMode = rs_chooser['mark_mode'][i];
			mark =  rs_chooser['mark_final'][i];
			markNote = rs_chooser['mark_note'][i];
			
			if( mark < 0){
				mark = 0;	
			}
			
			switch ( markNote ) {
				
				/* 正常成绩 */
				case "1": 
				
					mark_total = mark_total + mark;
					
					num_normal++;
					
					if ( mark gte 90 ){
						num1++;
					}
					else if ( mark gte 80 ){
						num2++;
					}
					else if ( mark gte 70 ){
						num3++;
					}
					else if ( mark gte 60 ){
						num4++;
					}
					else if ( mark gte 0 ){
						num5++;
					}
	
					break;
				
				/* 缺考 */
				case "2": 
					num_absent++;
					break;
				
				/* 缓考 */
				case "3": 
					num_delayed++;
					break;

				/* 免修 */
				case "4": 
					num_ignored++;
					break;
				
				/* 违纪 */
				case "9": 
					num_violated++;
					break;
				
			}
			
		}
		
		/* 二进制人数统计 */
		num_passed = num1 + num2 + num3 + num4;
		
		num_avg = mark_total/rs_chooser.recordCount;

	
	</cfscript>
</cfsilent>

<cfif checked >

	<cfloop from="1" to="#totlePageCount#" index="currentPage">

		<cfif currentPage GT 1><div class="page_break"></div></cfif>
		
		<div class="UIprintableTitle"><cfoutput>#rs_school.sch_name#</cfoutput>海外学院课程考核(卷面)成绩统计表</div>
		
		<table width="100%" border="0" cellpadding="1" cellspacing="0">
			<tr>
				<td>任课单位 <cfoutput>#rs_task.institute_name#</cfoutput></td>
				<td>教学班 <cfoutput>#rs_task.course_name#</cfoutput>-<cfoutput>#rs_task.tch_name#</cfoutput>-<cfoutput>#rs_task.cidx#</cfoutput></td>
				<td>教师 [<cfoutput>#rs_task.tch_id#</cfoutput>]<cfoutput>#rs_task.tch_name#</cfoutput></td>
				<td align="right">成绩记录 <cfoutput>#rs_chooser.recordCount#</cfoutput>条</td>
			</tr>
			<tr>
				<td>学期 <cfoutput>#rs_task.academic_year#</cfoutput>-<cfoutput>#rs_task.academic_term#</cfoutput></td>
				<td>课程 <cfif rs_task.course_code neq "">[<cfoutput>#rs_task.course_code#</cfoutput>]</cfif><cfoutput>#rs_task.course_name#</cfoutput></td>
				<td>学分 <cfoutput>#numberFormat(rs_task.course_credit, "_.__")#</cfoutput></td>
				<td align="right">第<cfoutput>#currentPage#</cfoutput>页 共<cfoutput>#totlePageCount2#</cfoutput>页</td>
			</tr>
		</table>
		
		<cfif currentPage eq totlePageCount AND totlePageCount eq totlePageCount2>
		
			<table class="UIprintable" width="100%" border="1" cellpadding="5" cellspacing="1">
				
				<tr>
					<td width="25%">百分制</td>
					<td width="25%">五级计分制</td>
					<td width="25%">二级计分制</td>
					<td width="25%">考试情况</td>
				</tr>
				<tr>
					<td>
						90分以上 
						<cfif num1 GT 0>: <cfoutput>#num1#</cfoutput> 人</cfif>
						<cfif num1 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num1 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>优秀
                         	<cfif num1 GT 0>: <cfoutput>#num1#</cfoutput> 人</cfif>
						<cfif num1 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num1 / num_normal, "_.__")# %</cfoutput></cfif>
                         </td>
                         
					<td>
						合格
						<cfif num_passed GT 0>: <cfoutput>#num_passed#</cfoutput> 人</cfif>
						<cfif num_passed GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num_passed / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>实考 <cfoutput>#num_normal#</cfoutput> 人</td>
				</tr>
				<tr>
					<td>
						80~89分以上 
						<cfif num2 GT 0>: <cfoutput>#num2#</cfoutput> 人</cfif>
						<cfif num2 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num2 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>良好<cfif num2 GT 0>: <cfoutput>#num2#</cfoutput> 人</cfif>
						<cfif num2 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num2 / num_normal, "_.__")# %</cfoutput></cfif></td>
					<td>
						不合格
						<cfif num5 GT 0>: <cfoutput>#num5#</cfoutput> 人</cfif>
						<cfif num5 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num5 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>缺考 <cfoutput>#num_absent#</cfoutput> 人</td>
				</tr>
				<tr>
					<td>
						70~79分
						<cfif num3 GT 0>: <cfoutput>#num3#</cfoutput> 人</cfif>
						<cfif num3 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num3 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>中等<cfif num3 GT 0>: <cfoutput>#num3#</cfoutput> 人</cfif>
						<cfif num3 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num3 / num_normal, "_.__")# %</cfoutput></cfif></td>
					<td>&nbsp;</td>
					<td>缓考 <cfoutput>#num_delayed#</cfoutput> 人</td>
				</tr>
				<tr>
					<td>
						60~69分
						<cfif num4 GT 0>: <cfoutput>#num4#</cfoutput> 人</cfif>
						<cfif num4 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num4 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>及格<cfif num4 GT 0>: <cfoutput>#num4#</cfoutput> 人</cfif>
						<cfif num4 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num4 / num_normal, "_.__")# %</cfoutput></cfif></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td>
						不及格
						<cfif num5 GT 0>: <cfoutput>#num5#</cfoutput> 人</cfif>
						<cfif num5 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num5 / num_normal, "_.__")# %</cfoutput></cfif>
					</td>
					<td>不及格<cfif num5 GT 0>: <cfoutput>#num5#</cfoutput> 人</cfif>
						<cfif num5 GT 0 and num_normal GT 0> / <cfoutput>#numberFormat( 100 * num5 / num_normal, "_.__")# %</cfoutput></cfif></td>
					<td>&nbsp;</td>
					<td>平均分数：<cfif rs_chooser.mark_mode eq '0'><cfoutput>#numberFormat(num_avg,"_.__")#</cfoutput><cfelse>&nbsp;</cfif></td>
				</tr>
			</table>
			
			<table class="UIprintable" width="100%" border="1" cellpadding="5" cellspacing="1">
				<tr class="sign">
					<td class="left">教师: __________________(签，章)</td>
					<td>考试/查日期: ______年______月______日</td>
				</tr>
			</table>
		</cfif>
		
		<div class="clear2px"></div>
		
		<table width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td></td>
				<td align="right"><img src="<cfoutput>#getContextRoot()#</cfoutput>/barcode/Print/<cfoutput>#tagCode#</cfoutput>.png" height="43"/></td>
			</tr>
		</table>
	
		<cfset pageRowBegin = pageRowBegin + rowPerPage />
		<cfset pageRowEnd = pageRowEnd + rowPerPage />
		<cfif pageRowEnd gt rs_chooser.recordCount> 
			<cfset pageRowEnd = rs_chooser.recordCount />
		</cfif>
	
	</cfloop>


</cfif>